<?php
class Slideshow extends CWidget
{
	public $assets_url = '';
	public $_wID = NULL;
	public function init()
	{
		$dir = dirname(__FILE__).'/assets';
		$this->assets_url = Yii::app()->getAssetManager()->publish($dir);
		$ClientScript = Yii::app()->getClientScript();
		$ClientScript->registerScriptFile("{$this->assets_url}/jquery.nivo.slider.pack.js");
		$ClientScript->registerCssFile("{$this->assets_url}/nivo-slider.css"); 
		parent::init();
	}
	public function run()
	{
		/* $params = Widgets::model()->findByPk($this->_wID);
		$data = @unserialize($params->params); */
		$data = FrontendBannersModel::model()->findAll('client_id=2');
		$this->render('default', array('data'=>$data));
	}
	public static function buildParams($params="")
	{
		$data = @unserialize($params);
		?>
		<script>
		$(document).ready(function(){
			var i = $('.inputs input').size() + 1;
			$('#add').click(function() {
				$('<div id="f'+i+'"><input type="text" class="field" name="Slideshow[]" value="" /><a onclick="$(\'#f'+i+'\').remove();">remove</a></div>').fadeIn('slow').appendTo('.inputs');
				i++;
			});
		})
		</script>
		<div class="inputs">
		<?php if($data){
			foreach ($data as $key => $value){
				?>
				<div id="f<?php echo $key+1;?>"><input type="text" name="Slideshow[]" value="<?php echo $value;?>" />&nbsp;<a onclick="$('#f<?php echo $key+1;?>').remove();">remove</a></div>
				<?php
			}
			
		}else{
			?>
			<div id="f1"><input type="text" name="Slideshow[]" value="" /></div>
			<?php
		}
		
		?>
		</div>
		<input type="hidden" name="widget" value="Slideshow" />
		<a id="add">Add</a>
		<?php
	}
	public function getParams($post)
	{
		return  serialize($post['Slideshow']);
	}
}